package com.ssy.lingxi.product.repository;

import com.ssy.lingxi.product.entity.Brand;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import java.util.List;

/**
 * 品牌持久化层
 *
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/28
 */
public interface BrandRepository extends JpaRepository<Brand, Long>, JpaSpecificationExecutor<Brand> {
    Page<Brand> findByMemberIdAndMemberRoleIdAndNameContainingAndStatusOrderByApplyTimeDesc(Long memberId, Long memberRoleId, String name, Integer status, Pageable page);

    Page<Brand> findByMemberIdAndMemberRoleIdAndNameContainingAndStatusAndIsEnableOrderByApplyTimeDesc(Long memberId, Long memberRoleId, String name, Integer status, Boolean isEnable, Pageable page);

    Page<Brand> findByMemberIdAndMemberRoleIdAndStatusAndIsEnableOrderByApplyTimeDesc(Long memberId, Long memberRoleId, Integer status, Boolean isEnable, Pageable page);

    Page<Brand> findByMemberIdAndMemberRoleIdAndNameContainingOrderByApplyTimeDesc(Long memberId, Long memberRoleId, String name, Pageable page);

    Boolean existsByMemberIdAndMemberRoleIdAndNameAndIdNot(Long memberId, Long memberRoleId, String name, Long id);

    Boolean existsBySourceBrandId(Long sourceBrandId);

    Boolean existsBySourceBrandIdAndIdNot(Long sourceBrandId, Long id);

    Boolean existsByMemberIdAndMemberRoleIdAndName(Long memberId, Long memberRoleId, String name);

    Page<Brand> findByMemberIdAndMemberRoleIdAndStatusAndTypeAndNameContainingAndMemberNameContainingOrderByApplyTimeDesc(Long memberId, Long memberRoleId, Integer status, Integer code, String name, String memberName, Pageable page);

    List<Brand> findByMemberIdAndMemberRoleIdAndStatusAndIsEnableOrderByApplyTimeDesc(Long memberId, Long memberRoleId, Integer status, Boolean isEnable);

    /******************************************* 平台后台 *****************************************************/

    Page<Brand> findByNameContainingAndStatusOrderByApplyTimeDesc(String name, Integer status, Pageable page);

    Page<Brand> findByNameContainingAndAndStatusNotOrderByApplyTimeDesc(String name, Integer not_status, Pageable page);

    Page<Brand> findByNameContainingAndStatusAndIsEnableOrderByApplyTimeDesc(String name, Integer status, Boolean isEnable, Pageable page);

    Page<Brand> findByStatusAndIsEnableOrderByApplyTimeDesc(Integer status, Boolean isEnable, Pageable page);

    List<Brand> findByStatusAndIsEnable(Integer status, Boolean isEnable);

    Page<Brand> findByStatusAndTypeOrderByApplyTimeDesc(Integer status, Integer type, Pageable page);

    Page<Brand> findByMemberIdAndMemberRoleIdAndStatusAndTypeOrderByApplyTimeDesc(Long memberId, Long memberRoleId, Integer status, Integer code, Pageable page);


}
